<template>
  <transition name="slide">
    <music-list :title="title" :bgImage="bgImage" :songs="hotsongs"></music-list>
  </transition>
</template>

<script>
import { mapState } from 'vuex'
import MusicList from '@/components/common/MusicList'
export default {
  components: {
    MusicList
  },
  data () {
    return {
      hotsongs: [] // 歌手热门歌曲
    }
  },
  methods: {
    // 检查是否存在singer对象
    checkSinger () {
      if (!this.singer.singer_id) {
        // 没有this.singer.id则自动跳转singer
        this.$router.back()
      }
    },
    // 获取歌手热门歌曲
    async getSongs () {
      // 先置空再请求 出现加载状态
      this.hotsongs = []
      const { data: { data: res } } = await this.$http.get('/api/singer/songs?num=50&singermid=' + this.singer.singer_mid)
      this.hotsongs = res.list
    }
  },
  computed: {
    ...mapState(['singer']),
    title () {
      return this.singer.singer_name
    },
    bgImage () {
      return this.singer.singer_pic
    }
  },
  watch: {
    singer () {
      this.getSongs()
    }
  },
  mounted () {
    this.checkSinger()
    this.getSongs()
  }
}
</script>

<style lang="stylus" scoped>
.slide-enter, .slide-leave-to {
  transform: translateX(100%);
}
.slide-enter-active, .slide-leave-active {
  transition: all .3s;
}
</style>
